//
//  AEMyExchangeViewController.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/13.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEMyExchangeViewController.h"
#import "AEMyExchangeViewModel.h"
#import "AEMyExchangeViewCell.h"

@interface AEMyExchangeViewController ()
@property (nonatomic, strong) AEMyExchangeViewModel *viewModel;
@end

@implementation AEMyExchangeViewController

- (void)dealloc {
    debugMethod();
}

- (void)initWithVar {
    [super initWithVar];
    
}

- (void)initWithViewModel {
    _viewModel = [AEMyExchangeViewModel new];
    [_viewModel setupData];
}

- (void)initWithSubView {
    [super initWithSubView];
    
    self.view.backgroundColor = kWhiteColor;
//    self.baseTableView.hidden = YES;
    self.baseTableView.backgroundColor = [UIColor colorWithHexString:@"#F6F8F8"];
    [self.baseTableView registerClass:[AEMyExchangeViewCell class] forCellReuseIdentifier:[AEMyExchangeViewCell className]];
    self.baseTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self hiddenFooterView:YES];
}

- (void)initWithFooterView {
    [super initWithFooterView];
    CGRect frame = CGRectMake(0, 0, kScreenW, 10 + IPHONEX_BOTTOM_SPACE);
    UIView *footerView = [[UIView alloc] initWithFrame:frame];
    footerView.backgroundColor = [UIColor colorWithHexString:@"#F6F8F8"];
    self.baseTableView.tableFooterView = footerView;
}

/// 确认领取
/// - Parameter model: model description
- (void)actionWithDrawDown:(AEMyExchangeModel *)model {
    [SVProgressHUD showInfoWithStatus:@"确认领取"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.viewModel.dataList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    AEMyExchangeModel *model = [self.viewModel.dataList objectOrNilAtIndex:indexPath.row];
    if ([model.status isEqualToString:@"1"]) { // 待领取
        return kAEMyExchangeViewCellHeight;
    }
    
    return kAEMyExchangeViewCellNoHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AEMyExchangeModel *model = [self.viewModel.dataList objectOrNilAtIndex:indexPath.row];
    AEMyExchangeViewCell *cell = [AEMyExchangeViewCell cellForTableView:tableView indexPath:indexPath];
    [cell updateCellData:model];
    @weakify(self);
    cell.touchDrawDownBlock = ^{
        @strongify(self);
        [self actionWithDrawDown:model];
    };
    return cell;
}

@end
